####Recoding variables and preparing the data for analyses

# Download required packages
install.packages("foreign", dependencies=TRUE)
install.packages("readxl", dependencies=TRUE)
install.packages("tidyverse", dependencies=TRUE)
install.packages("texreg", dependencies=TRUE)
install.packages("gridtext", dependencies=TRUE)
install.packages("gridExtra", dependencies=TRUE)
install.packages("patchwork", dependencies=TRUE)
install.packages("nnet", dependencies=TRUE)
install.packages("estimatr", dependencies=TRUE)
install.packages("interflex", dependencies=TRUE)
install.packages("janitor", dependencies=TRUE)

library(foreign)
library(readxl)
library(tidyverse)
library(texreg)
library(gridtext)
library(gridExtra)
library(patchwork)
require(nnet)
library(estimatr)
library(interflex)
library(janitor)

options(scipen=99)

##Coding the first wave of the Australian study

#set working directory
setwd("~/Media_BJPolS_replication_files")

#read in raw data
data<-read.csv("Survation Australia Survey 2020.csv")

names(data)

data$party[data$ge19=="Liberal"]<-1
data$party[data$ge19=="Labor"]<-2
data$party[data$ge19=="Liberal National"]<-1
data$party[data$ge19=="National"]<-1
data$party[data$ge19=="Country Liberal"]<-1
data$party[data$ge19=="One Nation"]<-3
data$party[data$ge19=="Katters Australian"]<-3
data$party[data$ge19=="Greens"]<-4
data$party[data$ge19=="United Australia"]<-5
data$party[data$ge19=="Centre Alliance"]<-5
data$party[data$ge19=="Independents"]<-5
data$party[data$ge19=="Other"]<-5
data$party[data$ge19=="Cant remember"]<-5
data$party[data$ge19=="Was not old enough to vote"]<-5
data$party[data$ge19=="Refused"]<-5

data$age_num<-as.numeric(data$age)
data$age_num[data$age=="85+"]<-85

data$Cottrell_opinion[data$q6=="Very respectable"]<-1
data$Cottrell_opinion[data$q6=="Quite respectable"]<-1
data$Cottrell_opinion[data$q6=="Don't know"]<-NA
data$Cottrell_opinion[data$q6==""]<-NA
data$Cottrell_opinion[data$q6=="Not that respectable"]<-1
data$Cottrell_opinion[data$q6=="Not at all respectable"]<-1

data$Cottrell_respectable[data$q6=="Very respectable"]<-1
data$Cottrell_respectable[data$q6=="Quite respectable"]<-1
data$Cottrell_respectable[data$q6=="Don't know"]<-0
data$Cottrell_respectable[data$q6==""]<-0
data$Cottrell_respectable[data$q6=="Not that respectable"]<-0
data$Cottrell_respectable[data$q6=="Not at all respectable"]<-0

data$Cottrell_unrespectable[data$q6=="Very respectable"]<-0
data$Cottrell_unrespectable[data$q6=="Quite respectable"]<-0
data$Cottrell_unrespectable[data$q6=="Don't know"]<-0
data$Cottrell_unrespectable[data$q6==""]<-0
data$Cottrell_unrespectable[data$q6=="Not that respectable"]<-1
data$Cottrell_unrespectable[data$q6=="Not at all respectable"]<-1

data$Cottrell_dontknow[data$q6=="Very respectable"]<-0
data$Cottrell_dontknow[data$q6=="Quite respectable"]<-0
data$Cottrell_dontknow[data$q6=="Don't know"]<-1
data$Cottrell_dontknow[data$q6==""]<-1
data$Cottrell_dontknow[data$q6=="Not that respectable"]<-0
data$Cottrell_dontknow[data$q6=="Not at all respectable"]<-0

data$Cottrell3cat[data$q6=="Very respectable"]<-1
data$Cottrell3cat[data$q6=="Quite respectable"]<-1
data$Cottrell3cat[data$q6=="Don't know"]<-2
data$Cottrell3cat[data$q6==""]<-2
data$Cottrell3cat[data$q6=="Not that respectable"]<-0
data$Cottrell3cat[data$q6=="Not at all respectable"]<-0

data$tr_interview[data$RAND=="BC Sky News"]<-1
data$tr_interview[data$RAND=="BC Youtube"]<-1
data$tr_interview[data$RAND=="WR Youtube"]<-0
data$tr_interview[data$RAND=="WR Sky News"]<-0

data$tr_platform[data$RAND=="BC Sky News"]<-1
data$tr_platform[data$RAND=="BC Youtube"]<-0
data$tr_platform[data$RAND=="WR Youtube"]<-0
data$tr_platform[data$RAND=="WR Sky News"]<-1

data$tr[data$RAND=="BC Sky News"]<-4
data$tr[data$RAND=="BC Youtube"]<-3
data$tr[data$RAND=="WR Youtube"]<-1
data$tr[data$RAND=="WR Sky News"]<-2

data$treatment[data$RAND=="BC Sky News"]<-"4. Interview Sky News"
data$treatment[data$RAND=="BC Youtube"]<-"3. Interview Youtube"
data$treatment[data$RAND=="WR Youtube"]<-"1. Weather Youtube"
data$treatment[data$RAND=="WR Sky News"]<-"2. Weather Sky News"


data$values<-as.numeric(data$q9)
data$values[data$q9=="1 - totally disagree"]<-1
data$values[data$q9=="Don't know"]<-NA
data$values[data$q9=="10 - totally agree"]<-10

data$norms_1<-as.numeric(data$q7_1)
data$norms_2<-as.numeric(data$q7_2)
data$norms_3<-as.numeric(data$q7_3)
data$norms_4<-as.numeric(data$q7_4)

data$attitudes_1<-as.numeric(data$q8_1)
data$attitudes_1[data$q8_1=="1 - totally disagree"]<-1
data$attitudes_1[data$q8_1=="10 - totally agree"]<-10

data$attitudes_2<-as.numeric(data$q8_2)
data$attitudes_2[data$q8_2=="1 - totally disagree"]<-1
data$attitudes_2[data$q8_2=="10 - totally agree"]<-10

data$attitudes_3<-as.numeric(data$q8_3)
data$attitudes_3[data$q8_3=="1 - totally disagree"]<-1
data$attitudes_3[data$q8_3=="10 - totally agree"]<-10

data$attitudes_4<-as.numeric(data$q8_4)
data$attitudes_4[data$q8_4=="1 - totally disagree"]<-1
data$attitudes_4[data$q8_4=="10 - totally agree"]<-10

data$attitudes_pre_1[data$q1_1=="Strongly agree"]<-5
data$attitudes_pre_1[data$q1_1=="Somewhat agree"]<-4
data$attitudes_pre_1[data$q1_1=="Neither agree nor disagree"]<-3
data$attitudes_pre_1[data$q1_1=="Somewhat disagree"]<-2
data$attitudes_pre_1[data$q1_1=="Strongly disagree"]<-1
data$attitudes_pre_1[data$q1_1=="Don't know"]<-3

data$attitudes_pre_2[data$q1_2=="Strongly agree"]<-5
data$attitudes_pre_2[data$q1_2=="Somewhat agree"]<-4
data$attitudes_pre_2[data$q1_2=="Neither agree nor disagree"]<-3
data$attitudes_pre_2[data$q1_2=="Somewhat disagree"]<-2
data$attitudes_pre_2[data$q1_2=="Strongly disagree"]<-1
data$attitudes_pre_2[data$q1_2=="Don't know"]<-3

data$attitudes_pre_3[data$q1_3=="Strongly agree"]<-5
data$attitudes_pre_3[data$q1_3=="Somewhat agree"]<-4
data$attitudes_pre_3[data$q1_3=="Neither agree nor disagree"]<-3
data$attitudes_pre_3[data$q1_3=="Somewhat disagree"]<-2
data$attitudes_pre_3[data$q1_3=="Strongly disagree"]<-1
data$attitudes_pre_3[data$q1_3=="Don't know"]<-3

data$attitudes_pre_4[data$q1_4=="Strongly agree"]<-5
data$attitudes_pre_4[data$q1_4=="Somewhat agree"]<-4
data$attitudes_pre_4[data$q1_4=="Neither agree nor disagree"]<-3
data$attitudes_pre_4[data$q1_4=="Somewhat disagree"]<-2
data$attitudes_pre_4[data$q1_4=="Strongly disagree"]<-1
data$attitudes_pre_4[data$q1_4=="Don't know"]<-3

data$attitudes_pre_5[data$q1_5=="Strongly agree"]<-5
data$attitudes_pre_5[data$q1_5=="Somewhat agree"]<-4
data$attitudes_pre_5[data$q1_5=="Neither agree nor disagree"]<-3
data$attitudes_pre_5[data$q1_5=="Somewhat disagree"]<-2
data$attitudes_pre_5[data$q1_5=="Strongly disagree"]<-1
data$attitudes_pre_5[data$q1_5=="Don't know"]<-3

data$attitudes_pre_6[data$q1_6=="Strongly agree"]<-5
data$attitudes_pre_6[data$q1_6=="Somewhat agree"]<-4
data$attitudes_pre_6[data$q1_6=="Neither agree nor disagree"]<-3
data$attitudes_pre_6[data$q1_6=="Somewhat disagree"]<-2
data$attitudes_pre_6[data$q1_6=="Strongly disagree"]<-1
data$attitudes_pre_6[data$q1_6=="Don't know"]<-3

data$attitudes_scale=(data$attitudes_1+data$attitudes_2+data$attitudes_3+data$attitudes_4)/40

data$attitudes_pre_scale=(data$attitudes_pre_1+data$attitudes_pre_2+data$attitudes_pre_3+data$attitudes_pre_4+data$attitudes_pre_5+data$attitudes_pre_6)/30

data$norms_scale=(data$norms_1+data$norms_2+data$norms_3+data$norms_4)/4


data$mis_attitudes[is.na(data$attitudes_scale)]<-1
data$mis_attitudes[!is.na(data$attitudes_scale)]<-0

data$mis_norms[is.na(data$norms_scale)]<-1
data$mis_norms[!is.na(data$norms_scale)]<-0

data$mis_actor=0
data$mis_actor[data$q6==""]<-1
data$mis_actor[data$q6=="Don't know"]<-1

data$wave <- 1

mydata1 = select(data, region, sex, age, education, ge19, party, age_num, Cottrell_opinion, Cottrell_respectable, Cottrell_unrespectable, Cottrell_dontknow, Cottrell3cat, tr_interview, tr_platform, tr, treatment, attitudes_pre_scale, attitudes_scale, norms_scale, mis_attitudes, mis_norms, mis_actor, attitudes_1,attitudes_2, attitudes_3, attitudes_4, norms_1, norms_2, norms_3, norms_4,
                 wave)
write.csv(mydata1,'data_2020.csv')

## Coding the second wave of the Australian study
data2<-read.csv("Survation Australia Survey 2022.csv")

names(data2)

data2$party[data2$ge19=="Liberal"]<-1
data2$party[data2$ge19=="Labor"]<-2
data2$party[data2$ge19=="Liberal National"]<-1
data2$party[data2$ge19=="National"]<-1
data2$party[data2$ge19=="Country Liberal"]<-1
data2$party[data2$ge19=="One Nation"]<-3
data2$party[data2$ge19=="Katters Australian"]<-3
data2$party[data2$ge19=="Greens"]<-4
data2$party[data2$ge19=="United Australia"]<-5
data2$party[data2$ge19=="Centre Alliance"]<-5
data2$party[data2$ge19=="Independents"]<-5
data2$party[data2$ge19=="Other"]<-5
data2$party[data2$ge19=="Can't remember"]<-5
data2$party[data2$ge19=="Was not old enough to vote"]<-5
data2$party[data2$ge19=="Refused"]<-5

data2$age_num<-as.numeric(data2$age)
data2$age_num[data2$age=="85+"]<-85


data2$mainstreamYT[data2$q3.4_pre=="5 - Very mainstream"]<-5
data2$mainstreamYT[data2$q3.4_pre=="4"]<-4
data2$mainstreamYT[data2$q3.4_pre=="3"]<-3
data2$mainstreamYT[data2$q3.4_pre=="2"]<-2
data2$mainstreamYT[data2$q3.4_pre=="1 - Not mainstream at all"]<-1
data2$mainstreamYT[data2$q3.4_post=="5 - Very mainstream"]<-5
data2$mainstreamYT[data2$q3.4_post=="4"]<-4
data2$mainstreamYT[data2$q3.4_post=="3"]<-3
data2$mainstreamYT[data2$q3.4_post=="2"]<-2
data2$mainstreamYT[data2$q3.4_post=="1 - Not mainstream at all"]<-1

data2$mainstream[data2$q3.3_pre=="5 - Very mainstream"]<-5
data2$mainstream[data2$q3.3_pre=="4"]<-4
data2$mainstream[data2$q3.3_pre=="3"]<-3
data2$mainstream[data2$q3.3_pre=="2"]<-2
data2$mainstream[data2$q3.3_pre=="1 - Not mainstream at all"]<-1
data2$mainstream[data2$q3.3_post=="5 - Very mainstream"]<-5
data2$mainstream[data2$q3.3_post=="4"]<-4
data2$mainstream[data2$q3.3_post=="3"]<-3
data2$mainstream[data2$q3.3_post=="2"]<-2
data2$mainstream[data2$q3.3_post=="1 - Not mainstream at all"]<-1

data2$mainstreamABC[data2$q3.1_pre=="5 - Very mainstream"]<-5
data2$mainstreamABC[data2$q3.1_pre=="4"]<-4
data2$mainstreamABC[data2$q3.1_pre=="3"]<-3
data2$mainstreamABC[data2$q3.1_pre=="2"]<-2
data2$mainstreamABC[data2$q3.1_pre=="1 - Not mainstream at all"]<-1
data2$mainstreamABC[data2$q3.1_post=="5 - Very mainstream"]<-5
data2$mainstreamABC[data2$q3.1_post=="4"]<-4
data2$mainstreamABC[data2$q3.1_post=="3"]<-3
data2$mainstreamABC[data2$q3.1_post=="2"]<-2
data2$mainstreamABC[data2$q3.1_post=="1 - Not mainstream at all"]<-1

data2$trustworthy[data2$q4.3_pre=="5 - Very trustworthy"]<-5
data2$trustworthy[data2$q4.3_pre=="4"]<-4
data2$trustworthy[data2$q4.3_pre=="3"]<-3
data2$trustworthy[data2$q4.3_pre=="2"]<-2
data2$trustworthy[data2$q4.3_pre=="1 - Not trustworthy at all"]<-1
data2$trustworthy[data2$q4.3_post=="5 - Very trustworthy"]<-5
data2$trustworthy[data2$q4.3_post=="4"]<-4
data2$trustworthy[data2$q4.3_post=="3"]<-3
data2$trustworthy[data2$q4.3_post=="2"]<-2
data2$trustworthy[data2$q4.3_post=="1 - Not trustworthy at all"]<-1

data2$trustworthyYT[data2$q4.1_pre=="5 - Very trustworthy"]<-5
data2$trustworthyYT[data2$q4.1_pre=="4"]<-4
data2$trustworthyYT[data2$q4.1_pre=="3"]<-3
data2$trustworthyYT[data2$q4.1_pre=="2"]<-2
data2$trustworthyYT[data2$q4.1_pre=="1 - Not trustworthy at all"]<-1
data2$trustworthyYT[data2$q4.1_post=="5 - Very trustworthy"]<-5
data2$trustworthyYT[data2$q4.1_post=="4"]<-4
data2$trustworthyYT[data2$q4.1_post=="3"]<-3
data2$trustworthyYT[data2$q4.1_post=="2"]<-2
data2$trustworthyYT[data2$q4.1_post=="1 - Not trustworthy at all"]<-1

data2$trustworthyABC[data2$q4.4_pre=="5 - Very trustworthy"]<-5
data2$trustworthyABC[data2$q4.4_pre=="4"]<-4
data2$trustworthyABC[data2$q4.4_pre=="3"]<-3
data2$trustworthyABC[data2$q4.4_pre=="2"]<-2
data2$trustworthyABC[data2$q4.4_pre=="1 - Not trustworthy at all"]<-1
data2$trustworthyABC[data2$q4.4_post=="5 - Very trustworthy"]<-5
data2$trustworthyABC[data2$q4.4_post=="4"]<-4
data2$trustworthyABC[data2$q4.4_post=="3"]<-3
data2$trustworthyABC[data2$q4.4_post=="2"]<-2
data2$trustworthyABC[data2$q4.4_post=="1 - Not trustworthy at all"]<-1

data2$Cottrell_haveheard<-NA
data2$Cottrell_haveheard[data2$q2=="Have heard of"]<-1
data2$Cottrell_haveheard[data2$q2=="Not sure"]<-NA
data2$Cottrell_haveheard[data2$q2=="Have not heard of"]<-0

data2$Cottrell_opinion[data2$q5=="Very respectable"]<-1
data2$Cottrell_opinion[data2$q5=="Quite respectable"]<-1
data2$Cottrell_opinion[data2$q5=="Don't know"]<-NA
data2$Cottrell_opinion[data2$q5==""]<-NA
data2$Cottrell_opinion[data2$q5=="Not that respectable"]<-1
data2$Cottrell_opinion[data2$q5=="Not at all respectable"]<-1

data2$Cottrell3cat[data2$q5=="Very respectable"]<-1
data2$Cottrell3cat[data2$q5=="Quite respectable"]<-1
data2$Cottrell3cat[data2$q5=="Don't know"]<-2
data2$Cottrell3cat[data2$q5==""]<-2
data2$Cottrell3cat[data2$q5=="Not that respectable"]<-0
data2$Cottrell3cat[data2$q5=="Not at all respectable"]<-0

data2$Cottrell_dontknow[data2$q5=="Very respectable"]<-0
data2$Cottrell_dontknow[data2$q5=="Quite respectable"]<-0
data2$Cottrell_dontknow[data2$q5=="Don't know"]<-1
data2$Cottrell_dontknow[data2$q5==""]<-1
data2$Cottrell_dontknow[data2$q5=="Not that respectable"]<-0
data2$Cottrell_dontknow[data2$q5=="Not at all respectable"]<-0

data2$Cottrell_respectable[data2$q5=="Very respectable"]<-1
data2$Cottrell_respectable[data2$q5=="Quite respectable"]<-1
data2$Cottrell_respectable[data2$q5=="Don't know"]<-0
data2$Cottrell_respectable[data2$q5==""]<-0
data2$Cottrell_respectable[data2$q5=="Not that respectable"]<-0
data2$Cottrell_respectable[data2$q5=="Not at all respectable"]<-0

data2$Cottrell_unrespectable[data2$q5=="Very respectable"]<-0
data2$Cottrell_unrespectable[data2$q5=="Quite respectable"]<-0
data2$Cottrell_unrespectable[data2$q5=="Don't know"]<-0
data2$Cottrell_unrespectable[data2$q5==""]<-0
data2$Cottrell_unrespectable[data2$q5=="Not that respectable"]<-1
data2$Cottrell_unrespectable[data2$q5=="Not at all respectable"]<-1

data2$tr_interview[data2$rand1=="Interview Sky"]<-1
data2$tr_interview[data2$rand1=="Interview YouTube"]<-1
data2$tr_interview[data2$rand1=="Weather Sky"]<-0
data2$tr_interview[data2$rand1=="Weather YouTube"]<-0

data2$tr_platform[data2$rand1=="Interview Sky"]<-1
data2$tr_platform[data2$rand1=="Interview YouTube"]<-0
data2$tr_platform[data2$rand1=="Weather Sky"]<-1
data2$tr_platform[data2$rand1=="Weather YouTube"]<-0

data2$tr[data2$rand1=="Interview Sky"]<-4
data2$tr[data2$rand1=="Interview YouTube"]<-3
data2$tr[data2$rand1=="Weather YouTube"]<-1
data2$tr[data2$rand1=="Weather Sky"]<-2

data2$treatment[data2$rand1=="Interview Sky"]<-"4.Unchallenged SN Interview"
data2$treatment[data2$rand1=="Interview YouTube"]<-"3.Unchallenged YT Interview"
data2$treatment[data2$rand1=="Weather YouTube"]<-" 1.Weather Youtube"
data2$treatment[data2$rand1=="Weather Sky"]<-"2. Weather Sky News"

data2$norms_1<-as.numeric(data2$q6.1)

data2$norms_2<-as.numeric(data2$q6.2)

data2$norms_3<-as.numeric(data2$q6.3)

data2$norms_4<-as.numeric(data2$q6.4)

data2$attitudes_1<-as.numeric(data2$q7.1)
data2$attitudes_1[data2$q7.1=="1 - totally disagree"]<-1
data2$attitudes_1[data2$q7.1=="10 - totally agree"]<-10

data2$attitudes_2<-as.numeric(data2$q7.2)
data2$attitudes_2[data2$q7.2=="1 - totally disagree"]<-1
data2$attitudes_2[data2$q7.2=="10 - totally agree"]<-10

data2$attitudes_3<-as.numeric(data2$q7.3)
data2$attitudes_3[data2$q7.3=="1 - totally disagree"]<-1
data2$attitudes_3[data2$q7.3=="10 - totally agree"]<-10

data2$attitudes_4<-as.numeric(data2$q7.4)
data2$attitudes_4[data2$q7.4=="1 - totally disagree"]<-1
data2$attitudes_4[data2$q7.4=="10 - totally agree"]<-10

data2$attitudes_pre_1[data2$q1.1=="Strongly agree"]<-5
data2$attitudes_pre_1[data2$q1.1=="Somewhat agree"]<-4
data2$attitudes_pre_1[data2$q1.1=="Neither agree nor disagree"]<-3
data2$attitudes_pre_1[data2$q1.1=="Somewhat disagree"]<-2
data2$attitudes_pre_1[data2$q1.1=="Strongly disagree"]<-1
data2$attitudes_pre_1[data2$q1.1=="Don't know"]<-3

data2$attitudes_pre_2[data2$q1.2=="Strongly agree"]<-5
data2$attitudes_pre_2[data2$q1.2=="Somewhat agree"]<-4
data2$attitudes_pre_2[data2$q1.2=="Neither agree nor disagree"]<-3
data2$attitudes_pre_2[data2$q1.2=="Somewhat disagree"]<-2
data2$attitudes_pre_2[data2$q1.2=="Strongly disagree"]<-1
data2$attitudes_pre_2[data2$q1.2=="Don't know"]<-3

data2$attitudes_pre_3[data2$q1.3=="Strongly agree"]<-5
data2$attitudes_pre_3[data2$q1.3=="Somewhat agree"]<-4
data2$attitudes_pre_3[data2$q1.3=="Neither agree nor disagree"]<-3
data2$attitudes_pre_3[data2$q1.3=="Somewhat disagree"]<-2
data2$attitudes_pre_3[data2$q1.3=="Strongly disagree"]<-1
data2$attitudes_pre_3[data2$q1.3=="Don't know"]<-3

data2$attitudes_pre_4[data2$q1.4=="Strongly agree"]<-5
data2$attitudes_pre_4[data2$q1.4=="Somewhat agree"]<-4
data2$attitudes_pre_4[data2$q1.4=="Neither agree nor disagree"]<-3
data2$attitudes_pre_4[data2$q1.4=="Somewhat disagree"]<-2
data2$attitudes_pre_4[data2$q1.4=="Strongly disagree"]<-1
data2$attitudes_pre_4[data2$q1.4=="Don't know"]<-3

data2$attitudes_pre_5[data2$q1.5=="Strongly agree"]<-5
data2$attitudes_pre_5[data2$q1.5=="Somewhat agree"]<-4
data2$attitudes_pre_5[data2$q1.5=="Neither agree nor disagree"]<-3
data2$attitudes_pre_5[data2$q1.5=="Somewhat disagree"]<-2
data2$attitudes_pre_5[data2$q1.5=="Strongly disagree"]<-1
data2$attitudes_pre_5[data2$q1.5=="Don't know"]<-3

data2$attitudes_pre_6[data2$q1.6=="Strongly agree"]<-5
data2$attitudes_pre_6[data2$q1.6=="Somewhat agree"]<-4
data2$attitudes_pre_6[data2$q1.6=="Neither agree nor disagree"]<-3
data2$attitudes_pre_6[data2$q1.6=="Somewhat disagree"]<-2
data2$attitudes_pre_6[data2$q1.6=="Strongly disagree"]<-1
data2$attitudes_pre_6[data2$q1.6=="Don't know"]<-3


data2$check_platform<-NA
data2$check_platform[data2$q10=="Sky News" & data2$tr_platform==1]  <-1
data2$check_platform[data2$q10=="Sky News" & data2$tr_platform==0]  <-0
data2$check_platform[data2$q10=="YouTube Channel" & data2$tr_platform==1]  <-0
data2$check_platform[data2$q10=="YouTube Channel" & data2$tr_platform==0]  <-1
data2$check_platform[data2$q10=="ABC Channel"] <-0
data2$check_platform[data2$q10=="Channel 7"] <-0

data2$check_content<-NA
data2$check_content[data2$q9=="Interview with a political activist" & data2$tr_interview==1]<-1
data2$check_content[data2$q9=="Interview with a political activist" & data2$tr_interview==0]<-0
data2$check_content[data2$q9=="Weather report" & data2$tr_interview==1]<-0
data2$check_content[data2$q9=="Weather report" & data2$tr_interview==0]<-1
data2$check_content[data2$q9=="Interview with a political activist" & data2$tr_interview==0]<-0
data2$check_content[data2$q9=="Interview with a musician"] <-0
data2$check_content[data2$q9=="Sports programme"] <-0

data2$check<-NA
data2$check[data2$q9=="Interview with a political activist" & data2$q10=="YouTube Channel" & data2$tr_interview==1 & data2$tr_platform==0]  <-1
data2$check[data2$q9=="Interview with a political activist" & data2$q10=="YouTube Channel" & data2$tr_interview==1 & data2$tr_platform==1]  <-0
data2$check[data2$q9=="Interview with a political activist" & data2$q10=="YouTube Channel" & data2$tr_interview==0 & data2$tr_platform==1]  <-0
data2$check[data2$q9=="Interview with a political activist" & data2$q10=="YouTube Channel" & data2$tr_interview==0 & data2$tr_platform==0]  <-0
data2$check[data2$q9=="Interview with a political activist" & data2$q10=="Sky News" & data2$tr_interview==1 & data2$tr_platform==1]  <-1
data2$check[data2$q9=="Interview with a political activist" & data2$q10=="Sky News" & data2$tr_interview==1 & data2$tr_platform==0]  <-0
data2$check[data2$q9=="Interview with a political activist" & data2$q10=="Sky News" & data2$tr_interview==0 & data2$tr_platform==1]  <-0
data2$check[data2$q9=="Interview with a political activist" & data2$q10=="Sky News" & data2$tr_interview==0 & data2$tr_platform==0]  <-0
data2$check[data2$q9=="Weather report" & data2$q10=="YouTube Channel" & data2$tr_interview==0 & data2$tr_platform==0]  <-1
data2$check[data2$q9=="Weather report" & data2$q10=="YouTube Channel" & data2$tr_interview==0 & data2$tr_platform==1]  <-0
data2$check[data2$q9=="Weather report" & data2$q10=="YouTube Channel" & data2$tr_interview==1 & data2$tr_platform==0]  <-0
data2$check[data2$q9=="Weather report" & data2$q10=="YouTube Channel" & data2$tr_interview==1 & data2$tr_platform==1]  <-0
data2$check[data2$q9=="Weather report" & data2$q10=="Sky News" & data2$tr_interview==0 & data2$tr_platform==0]  <-0
data2$check[data2$q9=="Weather report" & data2$q10=="Sky News" & data2$tr_interview==1 & data2$tr_platform==0]  <-0
data2$check[data2$q9=="Weather report" & data2$q10=="Sky News" & data2$tr_interview==0 & data2$tr_platform==1]  <-1
data2$check[data2$q9=="Weather report" & data2$q10=="Sky News" & data2$tr_interview==1 & data2$tr_platform==1]  <-0
data2$check[data2$q9=="Sports programme"] <-0
data2$check[data2$q9=="Interview with a musician"] <-0
data2$check[data2$q10=="ABC Channel"] <-0
data2$check[data2$q10=="Channel 7"] <-0

data2$attention<-as.numeric(data2$q_att)
data2$attention[data2$q_att=="Strongly Disagree"]<-1
data2$attention[data2$q_att=="Neither Agree nor Disagree"]<-0
data2$attention[data2$q_att=="Somewhat Agree"]<-0
data2$attention[data2$q_att=="Somewhat Disagree"]<-0
data2$attention[data2$q_att=="Strongly Agree"]<-0

data2$attitudes_scale=(data2$attitudes_1+data2$attitudes_2+data2$attitudes_3+data2$attitudes_4)/40

data2$attitudes_pre_scale=(data2$attitudes_pre_1+data2$attitudes_pre_2+data2$attitudes_pre_3+data2$attitudes_pre_4+data2$attitudes_pre_5+data2$attitudes_pre_6)/30

data2$norms_scale=((data2$norms_1+data2$norms_2+data2$norms_3+data2$norms_4)/4)/100

data2$mis_attitudes[is.na(data2$attitudes_scale)]<-1
data2$mis_attitudes[!is.na(data2$attitudes_scale)]<-0

data2$mis_norms[is.na(data2$norms_scale)]<-1
data2$mis_norms[!is.na(data2$norms_scale)]<-0

data2$mis_actor<-0
data2$mis_actor[data2$q5==""]<-1
data2$mis_actor[data2$q5=="Don't know"]<-1

data2$wave <-2
mydata2 = select(data2, region, sex, age, education, ge19, party, age_num, Cottrell_opinion, Cottrell_respectable, Cottrell_unrespectable, Cottrell_dontknow, Cottrell3cat, tr_interview, tr_platform, tr, treatment, attitudes_pre_scale, attitudes_scale, norms_scale, mis_attitudes, mis_norms, mis_actor, attitudes_1,attitudes_2, attitudes_3, attitudes_4, norms_1, norms_2, norms_3, norms_4,
                 wave)

write.csv(mydata2,'data_2022.csv')
data_2022<-read.csv("data_2022.csv")
data_2020<-read.csv("data_2020.csv")


#Merge the two waves of the Australian study
common <- intersect(colnames(data_2020), colnames(data_2022))
data_combined <- rbind(data_2020[common], data_2022[common])

data_combined$norms_scale<-data_combined$norms_scale/100

names(data_combined)

table(data_combined$wave)

## Read in and recode the UK data

options(scipen=99)

uk<-read_excel("Survation_UK.xlsx")

uk$party[uk$ge2019=="Conservative"]<-1
uk$party[uk$ge2019=="Labour"]<-2
uk$party[uk$ge2019=="Brexit"]<-3
uk$party[uk$ge2019=="Green"]<-4
uk$party[uk$ge2019=="Liberal Democrats"]<-5
uk$party[uk$ge2019=="Scottish National Party"]<-6
uk$party[uk$ge2019=="Other"]<-7
uk$party[uk$ge2019=="Did not vote"]<-7

uk$brexit[uk$eu2016=="Remain"]<-1
uk$brexit[uk$eu2016=="Leave"]<-2
uk$brexit[uk$eu2016=="Did not vote"]<-3

uk$age_num<-as.numeric(uk$age)
uk$age_num[uk$age=="85+"]<-85

uk$mainstreamSN[uk$q3.1=="5 - Very mainstream"]<-5
uk$mainstreamSN[uk$q3.1=="4"]<-4
uk$mainstreamSN[uk$q3.1=="3"]<-3
uk$mainstreamSN[uk$q3.1=="2"]<-2
uk$mainstreamSN[uk$q3.1=="1 - Not mainstream at all"]<-1

uk$mainstreamYT[uk$q3.4=="5 - Very mainstream"]<-5
uk$mainstreamYT[uk$q3.4=="4"]<-4
uk$mainstreamYT[uk$q3.4=="3"]<-3
uk$mainstreamYT[uk$q3.4=="2"]<-2
uk$mainstreamYT[uk$q3.4=="1 - Not mainstream at all"]<-1

uk$mainstreamBBC[uk$q3.2=="5 - Very mainstream"]<-5
uk$mainstreamBBC[uk$q3.2=="4"]<-4
uk$mainstreamBBC[uk$q3.2=="3"]<-3
uk$mainstreamBBC[uk$q3.2=="2"]<-2
uk$mainstreamBBC[uk$q3.2=="1 - Not mainstream at all"]<-1

uk$mainstreamITV[uk$q3.3=="5 - Very mainstream"]<-5
uk$mainstreamITV[uk$q3.3=="4"]<-4
uk$mainstreamITV[uk$q3.3=="3"]<-3
uk$mainstreamITV[uk$q3.3=="2"]<-2
uk$mainstreamITV[uk$q3.3=="1 - Not mainstream at all"]<-1

uk$trustworthySN[uk$q4.1=="5 - Very trustworthy"]<-5
uk$trustworthySN[uk$q4.1=="4"]<-4
uk$trustworthySN[uk$q4.1=="3"]<-3
uk$trustworthySN[uk$q4.1=="2"]<-2
uk$trustworthySN[uk$q4.1=="1 - Not trustworthy at all"]<-1

uk$trustworthyYT[uk$q4.4=="5 - Very trustworthy"]<-5
uk$trustworthyYT[uk$q4.4=="4"]<-4
uk$trustworthyYT[uk$q4.4=="3"]<-3
uk$trustworthyYT[uk$q4.4=="2"]<-2
uk$trustworthyYT[uk$q4.4=="1 - Not trustworthy at all"]<-1

uk$trustworthyBBC[uk$q4.2=="5 - Very trustworthy"]<-5
uk$trustworthyBBC[uk$q4.2=="4"]<-4
uk$trustworthyBBC[uk$q4.2=="3"]<-3
uk$trustworthyBBC[uk$q4.2=="2"]<-2
uk$trustworthyBBC[uk$q4.2=="1 - Not trustworthy at all"]<-1

uk$trustworthyITV[uk$q4.3=="5 - Very trustworthy"]<-5
uk$trustworthyITV[uk$q4.3=="4"]<-4
uk$trustworthyITV[uk$q4.3=="3"]<-3
uk$trustworthyITV[uk$q4.3=="2"]<-2
uk$trustworthyITV[uk$q4.3=="1 - Not trustworthy at all"]<-1

uk$Robinson_dontknow[uk$q5=="Very respectable"]<-0
uk$Robinson_dontknow[uk$q5=="Quite respectable"]<-0
uk$Robinson_dontknow[uk$q5=="Don't know"]<-1
uk$Robinson_dontknow[uk$q5==""]<-1
uk$Robinson_dontknow[uk$q5=="Not that respectable"]<-0
uk$Robinson_dontknow[uk$q5=="Not at all respectable"]<-0

uk$Robinson_unrespectable[uk$q5=="Very respectable"]<-0
uk$Robinson_unrespectable[uk$q5=="Quite respectable"]<-0
uk$Robinson_unrespectable[uk$q5=="Don't know"]<-0
uk$Robinson_unrespectable[uk$q5==""]<-0
uk$Robinson_unrespectable[uk$q5=="Not that respectable"]<-1
uk$Robinson_unrespectable[uk$q5=="Not at all respectable"]<-1

uk$Robinson_respectable[uk$q5=="Very respectable"]<-1
uk$Robinson_respectable[uk$q5=="Quite respectable"]<-1
uk$Robinson_respectable[uk$q5=="Don't know"]<-0
uk$Robinson_respectable[uk$q5==""]<-0
uk$Robinson_respectable[uk$q5=="Not that respectable"]<-0
uk$Robinson_respectable[uk$q5=="Not at all respectable"]<-0

uk$Robinson3cat<-NA
uk$Robinson3cat[uk$q5=="Very respectable"]<-1
uk$Robinson3cat[uk$q5=="Quite respectable"]<-1
uk$Robinson3cat[uk$q5=="Don't know"]<-2
uk$Robinson3cat[uk$q5==""]<-2
uk$Robinson3cat[uk$q5=="Not that respectable"]<-0
uk$Robinson3cat[uk$q5=="Not at all respectable"]<-0

uk$tr_interview[uk$rand=="YT Interview Challenged"]<-1
uk$tr_interview[uk$rand=="Sky News Interview Challenged"]<-1
uk$tr_interview[uk$rand=="YT Interview Unchallenged"]<-1
uk$tr_interview[uk$rand=="Sky News Interview Unchallenged"]<-1
uk$tr_interview[uk$rand=="Sky News Weather"]<-0
uk$tr_interview[uk$rand=="YT Weather"]<-0

uk$tr_platform[uk$rand=="YT Interview Challenged"]<-0
uk$tr_platform[uk$rand=="Sky News Interview Challenged"]<-1
uk$tr_platform[uk$rand=="YT Interview Unchallenged"]<-0
uk$tr_platform[uk$rand=="Sky News Interview Unchallenged"]<-1
uk$tr_platform[uk$rand=="Sky News Weather"]<-1
uk$tr_platform[uk$rand=="YT Weather"]<-0

uk$tr_challenged[uk$rand=="YT Interview Challenged"]<-1
uk$tr_challenged[uk$rand=="Sky News Interview Challenged"]<-1
uk$tr_challenged[uk$rand=="YT Interview Unchallenged"]<-0
uk$tr_challenged[uk$rand=="Sky News Interview Unchallenged"]<-0
uk$tr_challenged[uk$rand=="Sky News Weather"]<-0
uk$tr_challenged[uk$rand=="YT Weather"]<-0

uk$tr[uk$rand=="YT Interview Challenged"]<-5 
uk$tr[uk$rand=="Sky News Interview Challenged"]<-6
uk$tr[uk$rand=="YT Interview Unchallenged"]<-3
uk$tr[uk$rand=="Sky News Interview Unchallenged"]<-4
uk$tr[uk$rand=="Sky News Weather"]<-2
uk$tr[uk$rand=="YT Weather"]<-1 

uk$challenge_bin[uk$rand=="YT Interview Challenged"]<-1 
uk$challenge_bin[uk$rand=="Sky News Interview Challenged"]<-1
uk$challenge_bin[uk$rand=="YT Interview Unchallenged"]<-0
uk$challenge_bin[uk$rand=="Sky News Interview Unchallenged"]<-0
uk$challenge_bin[uk$rand=="Sky News Weather"]<-NA
uk$challenge_bin[uk$rand=="YT Weather"]<-NA

uk$tr_cat[uk$rand=="YT Interview Challenged"]<-3
uk$tr_cat[uk$rand=="Sky News Interview Challenged"]<-3
uk$tr_cat[uk$rand=="YT Interview Unchallenged"]<-2
uk$tr_cat[uk$rand=="Sky News Interview Unchallenged"]<-2
uk$tr_cat[uk$rand=="Sky News Weather"]<-1
uk$tr_cat[uk$rand=="YT Weather"]<-1

uk$treatment<-NA
uk$treatment[uk$rand=="YT Interview Challenged"]<- "Challenged YT Itw"
uk$treatment[uk$rand=="Sky News Interview Challenged"]<- "Challenged SN Itw"
uk$treatment[uk$rand=="YT Interview Unchallenged"]<- "Unchallenged YT Itw"
uk$treatment[uk$rand=="Sky News Interview Unchallenged"]<- "Unchallenged SN Itw"
uk$treatment[uk$rand=="Sky News Weather"]<- "SN Weather"
uk$treatment[uk$rand=="YT Weather"]<- "YT Weather"

uk$norms_1<-as.numeric(uk$q6.1)
uk$norms_2<-as.numeric(uk$q6.2)
uk$norms_3<-as.numeric(uk$q6.3)
uk$norms_4<-as.numeric(uk$q6.4)
uk$norms_5<-as.numeric(uk$q6.5)

uk$attitudes_1<-as.numeric(uk$q9.1)
uk$attitudes_1[uk$q9.1=="1 - totally disagree"]<-1
uk$attitudes_1[uk$q9.1=="10 - totally agree"]<-10

uk$attitudes_2<-as.numeric(uk$q9.2)
uk$attitudes_2[uk$q9.2=="1 - totally disagree"]<-1
uk$attitudes_2[uk$q9.2=="10 - totally agree"]<-10

uk$attitudes_3<-as.numeric(uk$q9.3)
uk$attitudes_3[uk$q9.3=="1 - totally disagree"]<-1
uk$attitudes_3[uk$q9.3=="10 - totally agree"]<-10

uk$attitudes_4<-as.numeric(uk$q9.4)
uk$attitudes_4[uk$q9.4=="1 - totally disagree"]<-1
uk$attitudes_4[uk$q9.4=="10 - totally agree"]<-10

uk$attitudes_5<-as.numeric(uk$q9.5)
uk$attitudes_5[uk$q9.5=="1 - totally disagree"]<-1
uk$attitudes_5[uk$q9.5=="10 - totally agree"]<-10

uk$attitudes_pre_1<-as.numeric(uk$q1.1)
uk$attitudes_pre_1[uk$q1.1=="7 - Strongly agree"]<-7
uk$attitudes_pre_1[uk$q1.1=="1 - Strongly disagree"]<-1
uk$attitudes_pre_1[uk$q1.1=="Don't know"]<-4

uk$attitudes_pre_2<-as.numeric(uk$q1.2)
uk$attitudes_pre_2[uk$q1.2=="7 - Strongly agree"]<-7
uk$attitudes_pre_2[uk$q1.2=="1 - Strongly disagree"]<-1
uk$attitudes_pre_2[uk$q1.2=="Don't know"]<-4

uk$attitudes_pre_3<-as.numeric(uk$q1.3)
uk$attitudes_pre_3[uk$q1.3=="7 - Strongly agree"]<-7
uk$attitudes_pre_3[uk$q1.3=="1 - Strongly disagree"]<-1
uk$attitudes_pre_3[uk$q1.3=="Don't know"]<-4

uk$attitudes_pre_4<-as.numeric(uk$q1.4)
uk$attitudes_pre_4[uk$q1.4=="7 - Strongly agree"]<-7
uk$attitudes_pre_4[uk$q1.4=="1 - Strongly disagree"]<-1
uk$attitudes_pre_4[uk$q1.4=="Don't know"]<-4

uk$attitudes_pre_5<-as.numeric(uk$q1.5)
uk$attitudes_pre_5[uk$q1.5=="7 - Strongly agree"]<-7
uk$attitudes_pre_5[uk$q1.5=="1 - Strongly disagree"]<-1
uk$attitudes_pre_5[uk$q1.5=="Don't know"]<-4

uk$attitudes_pre_6<-as.numeric(uk$q1.6)
uk$attitudes_pre_6[uk$q1.6=="7 - Strongly agree"]<-7
uk$attitudes_pre_6[uk$q1.6=="1 - Strongly disagree"]<-1
uk$attitudes_pre_6[uk$q1.6=="Don't know"]<-4

uk$radical_facts_1<-NA
uk$radical_facts_1<-as.numeric(uk$q7.1)
uk$radical_facts_1[uk$q7.1=="1 - fully inaccurate"]<-1
uk$radical_facts_1[uk$q7.1=="10 - fully accurate"]<-10

uk$radical_facts_2<-NA
uk$radical_facts_2<-as.numeric(uk$q7.2)
uk$radical_facts_2[uk$q7.2=="1 - fully inaccurate"]<-1
uk$radical_facts_2[uk$q7.2=="10 - fully accurate"]<-10

uk$attention<-as.numeric(uk$q3)
uk$attention[uk$q3=="Strongly disagree"]<-1
uk$attention[uk$q3=="Neither agree nor disagree"]<-0
uk$attention[uk$q3=="Somewhat agree"]<-0
uk$attention[uk$q3=="Somewhat disagree"]<-0
uk$attention[uk$q3=="Strongly agree"]<-0

uk$accuracy<-as.numeric(uk$q10)
uk$accuracy[uk$q10=="Interview with a far-right political activist"]<-1
uk$accuracy[uk$q10=="Interview with a political activist"]<-0
uk$accuracy[uk$q10=="Weather report"]<-0
uk$accuracy[uk$q10=="Interview with a musician"]<-0
uk$accuracy[uk$q10=="Sports programme"]<-0

uk$attitudes_scale=(uk$attitudes_1+uk$attitudes_2+uk$attitudes_3+uk$attitudes_4+uk$attitudes_5)/50

uk$attitudes_pre_scale=(uk$attitudes_pre_1+uk$attitudes_pre_2+uk$attitudes_pre_3+uk$attitudes_pre_4+uk$attitudes_pre_5+uk$attitudes_pre_6)/42

uk$norms_scale=((uk$norms_1+uk$norms_2+uk$norms_3+uk$norms_4 + uk$norms_5)/5)/100

uk$radical_facts=(uk$radical_facts_1+uk$radical_facts_2)/2

uk$mis_attitudes[is.na(uk$attitudes_scale)]<-1
uk$mis_attitudes[!is.na(uk$attitudes_scale)]<-0

uk$mis_norms[is.na(uk$norms_scale)]<-1
uk$mis_norms[!is.na(uk$norms_scale)]<-0

uk$mis_actor<-0
uk$mis_actor[uk$q5==""]<-1
uk$mis_actor[uk$q5=="Don't know"]<-1

uk$check<-uk$checking
uk$check[uk$check=="Media Match Content Partial-Match"]<-"Media Match Content Match"
uk$check[uk$check=="Media Mismatch Content Partial-Match"]<-"Media Mismatch Content Match"


uk$check_content<-uk$checking
uk$check_content[uk$check=="Media Match Content Match"]<-1
uk$check_content[uk$check=="Media Mismatch Content Match"]<-1
uk$check_content[uk$check=="Media Match Content Mismatch"]<-0
uk$check_content[uk$check=="Media Mismatch Content Mismatch"]<-0
uk$check_content<-as.numeric(uk$check_content)

uk$check_platform<-uk$checking
uk$check_platform[uk$check=="Media Match Content Match"]<-1
uk$check_platform[uk$check=="Media Mismatch Content Match"]<-0
uk$check_platform[uk$check=="Media Match Content Mismatch"]<-1
uk$check_platform[uk$check=="Media Mismatch Content Mismatch"]<-0
uk$check_platform<-as.numeric(uk$check_platform)



#Save datasets
save(data_combined, file = "data_combined.RData")
save(uk, file = "uk.RData")
save(data2, file = "data2.RData")
